package com.example.demo2.config;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;

/**
 * Description:
 *
 * @author liuziyang
 * @date 2021/6/29 20:15
 */
@Configuration
public class DataSourceConfig {
    /**
     * 解决druid 日志报错：discard long time none received connection:xxx
     * Set properties.
     */
    @PostConstruct
    public void setProperties() {
        System.setProperty("druid.mysql.usePingMethod", "false");
    }

    @Bean("dataSource")
    public DataSource druidDataSource() {
        return DruidDataSourceBuilder.create().build();
    }
}
